package com.aaa.home.service.Impl;

import com.aaa.common.entity.home.TbHeadNav;
import com.aaa.common.entity.home.TbLink;
import com.aaa.common.entity.home.TblZone;
import com.aaa.common.vo.Result;
import com.aaa.home.dao.TbHeadNavDao;
import com.aaa.home.service.TbHeadNavService;
import com.aaa.home.vo.HeadNavkVo;
import com.aaa.home.vo.Zone.HeadNavAddVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * @author ：Mickey
 * @date ：Created in 2022/12/8 1:35
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class TbHeadNavServiceImpl implements TbHeadNavService {

    @Autowired
    private TbHeadNavDao headNavDao;

    @Autowired
    private TbHeadNavService headNavService;

    @Override
    public Result getAllHeadNavPage(HeadNavkVo headNavkVo, Integer current, Integer pageSize) {
        IPage<TbHeadNav> page = new Page<>(current, pageSize);
        QueryWrapper<TbHeadNav> wrapper = new QueryWrapper<>();
        if(StringUtils.hasText(headNavkVo.getHeadName())){

            wrapper.like("head_name",headNavkVo.getHeadName());
        }
        if (headNavkVo.getIsDisable()!=null){
            wrapper.eq("diable",headNavkVo.getIsDisable());
        }
        IPage<TbHeadNav> page1 = headNavDao.selectPage(page,wrapper);
        return new Result(2000,"分页查询头部导航成功",page1);
    }

    @Override
    public Result deleteheadNavBtId(String headId) {
        int i = headNavDao.deleteById(headId);
        System.out.println(i+"删除头部导航是否成功");
        return new Result(2000,"删除头部导航成功",null);
    }

    @Override
    public Result updateheadNavStatus(String headId, String isDisable) {
        TbHeadNav tbHeadNav = new TbHeadNav(headId, isDisable);
        int i = headNavDao.updateById(tbHeadNav);
        return new Result(2000,"头部导航状态修改成功",null);
    }

    @Override
    public Result addHeadNav(HeadNavAddVo headNavAddVo) {
        System.out.println(headNavAddVo+"aaaaaaaaaaaaaaaaaaaaaaaaa");
        String headName = headNavAddVo.getHeadName();
        String href = headNavAddVo.getHref();
        QueryWrapper<TbHeadNav> wrapper = new QueryWrapper<>();
        wrapper.eq("head_name",headName);
        TbHeadNav selectHeadNav = headNavDao.selectOne(wrapper);
        if(selectHeadNav!=null){
            headNavService.deleteheadNavBtId(selectHeadNav.getHeadId());
        }
        TbHeadNav tbHeadNav = new TbHeadNav(headName,href,"0","0");
        int insert = headNavDao.insert(tbHeadNav);
        return new Result(2000,"添加/修改头部连接成功",null);
    }
}
